#include "line.h"
#include <iostream>
using namespace std;

//私有的内部类
//所以对于LineImpl*来说，深拷贝更为合理一些
//Impl:implementation
//关于Line的功能的实现全部都是位于LineImpl类中的
class Line::LineImpl{
public:
    //应该再定义一个Point类
    LineImpl(int x1, int y1, int x2, int y2)
    :_pt1(x1, y1)
    ,_pt2(x2, y2)
    {

    }

    void printline(){
        _pt1.print();
        cout << "----->";
        _pt2.print();
        cout << endl;
    }


private:
    class Point{
    public:
        Point(int x, int y)
        :_x(x)
        ,_y(y)
        {

        }
        void print(){
            cout << "(" << _x << "," << _y << ")";
        }
    private:
        int _x;
        int _y;
    };

    Point _pt1;
    Point _pt2;
};

//指针数据成员初始化 深拷贝
Line::Line(int x1, int y1, int x2, int y2)
:_impl(new LineImpl(x1, y1, x2, y2))
{

}

Line::~Line(){
    if(_impl){
        delete _impl;
        _impl = nullptr;
    }
}
//因为Line仅持有_impl指针数据成员
//该函数的功能需要进一步委托给_impl来处理
void Line::printLine(){
    _impl->printline();
}
